<template>
  <div style="height: 100%">
    <el-container style="height: 100%; border: 1px solid #304156">
      <el-aside
        :width="isCollapse ? '200' : ''"
        style="background-color: #304156"
      >
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          :collapse="isCollapse"
          background-color="#304156"
          text-color="#fff"
          active-text-color="#2aa1ff"
          router
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-s-cooperation"></i>
              {{ isCollapse ? "" : "1688" }}
            </template>
            <el-menu-item-group>
              <template slot="title">商品</template>
              <el-menu-item index="/1688/shop">1688选取商品</el-menu-item>
              <el-menu-item index="/1688/library">我的商品库</el-menu-item>
              <el-menu-item index="/1688/follow">我关注的商品</el-menu-item>
              <el-menu-item index="/1688/order">我的字节订单</el-menu-item>
              <el-menu-item index="/1688/order/corder"
              >手动创建字节订单
              </el-menu-item
              >
              <el-menu-item index="/1688/order/1">我的1688订单</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-menu"></i>
              {{ isCollapse ? "" : "抖店" }}
            </template>
            <el-menu-item-group>
              <template slot="title">商品</template>
              <el-menu-item index="/zj/goods/list">商品信息</el-menu-item>
              <el-menu-item index="/zj/order/list">订单处理</el-menu-item>
              <el-menu-item index="/zj/order/listInfo">订单信息</el-menu-item>
              <el-menu-item index="2-2">售后处理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-setting"></i>
              {{ isCollapse ? "" : "绑定" }}
            </template>
            <el-menu-item-group>
              <template slot="title">账号</template>
              <el-menu-item index="/zj/oauth/oauth">我的抖店账号</el-menu-item>
              <el-menu-item index="/1688/account">我的1688账号</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group title="个人">
              <el-menu-item index="3-3">个人中心</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header
          style="
            font-size: 12px;
            background: #ffffff;
            border-bottom: 1px solid #e6e6e6;
          "
        >
          <el-button
            type="primary"
            @click="isCollapse = !isCollapse"
            :icon="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
          ></el-button>
          <span style="float: right">
            <el-dropdown>
              <i class="el-icon-setting" style="margin-right: 15px">
                <el-badge
                  v-show="messageTotal > 0"
                  is-dot
                  class="item"
                ></el-badge>
              </i>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item>
                  <el-badge :value="messageTotal" class="item">
                    <span @click="$router.push({ path: '/message/1688' })"
                    >我的消息</span
                    >
                  </el-badge>
                </el-dropdown-item>
                <el-dropdown-item>
                  <div @click="signOut">退出登录</div>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <span>root</span>
          </span>
        </el-header>

        <el-main
          v-loading="GLOBAL.BASE_LOADING"
          element-loading-background="rgba(0, 0, 0, 0.5)"
          element-loading-text="加载中"
        >
          <el-breadcrumb style="margin: 10px 20px" separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>
              <a href="/">{{ $route.meta }}</a>
            </el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.name }}</el-breadcrumb-item>
          </el-breadcrumb>
          <keep-alive
            exclude="shopDetail,showOrder,aliToTt,followList,order,library,orderDetail"
          >
            <router-view/>
          </keep-alive>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style>
  .el-header {
    background-color: #b3c0d1;
    color: #333;
    line-height: 60px;
  }

  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
</style>

<script>
  export default {
    beforeCreate () {
      // 获取jti
      const token = localStorage.getItem('token')
      if (!token) {
        this.$router.push({name: 'Login'})
      }
    },
    data() {
      return {
        pictLoading: false,
        isCollapse: false,
        messageTotal: 0,
      };
    },
    methods: {
//      getMessageTotal() {
//        await this.$http
//          .get(``)
//          .then((res) => {
//          })
//          .catch((err) => console.log(err));
//      },
      signOut () {
        // 清除jit
        localStorage.clear()
        // 提示
        this.$message.success('退出成功')
        this.$router.push({path: '/login'})
      }
    },
  };
</script>
